-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[CIR] Support more declarations without any codegen #151076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This patch adds or completes support for a couple of top level declaration types that don't emit any code: Most notably these include Concepts, static_assert and type aliases.
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clangir Author: Morris Hafner (mmha) ChangesThis patch adds or completes support for a couple of top level declaration types that don't emit any code: Most notably these include Concepts, static_assert and type aliases. Full diff: https://github.com/llvm/llvm-project/pull/151076.diff 2 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 350270518156e..6f32c9e2e2f8d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1267,8 +1267,13 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
break;
// No code generation needed.
- case Decl::UsingShadow:
+ case Decl::ClassTemplate:
+ case Decl::Concept:
case Decl::Empty:
+ case Decl::FunctionTemplate:
+ case Decl::StaticAssert:
+ case Decl::TypeAliasTemplate:
+ case Decl::UsingShadow:
break;
case Decl::CXXConstructor:
diff --git a/clang/test/CIR/CodeGen/empty.cpp b/clang/test/CIR/CodeGen/empty.cpp
new file mode 100644
index 0000000000000..7e61f4b1211a3
--- /dev/null
+++ b/clang/test/CIR/CodeGen/empty.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
+
+// These declarations shouldn't emit any code. Therefore the module is expected to be empty.
+
+template<typename T>
+concept some_concept = true;
+
+template<some_concept T>
+class class_template {};
+
+; // Empty declaration
+
+template<typename T>
+void function_template();
+
+static_assert(true, "top level static assert");
+
+template<typename T>
+using type_alias = T;
+
+namespace N {
+ using ::class_template; // UsingShadow
+}
+
+// CIR: module {{.*}} {
+// CIR-NEXT: }
\ No newline at end of file
|
| case Decl::Empty: | ||
| case Decl::FunctionTemplate: | ||
| case Decl::StaticAssert: | ||
| case Decl::TypeAliasTemplate: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add Decl::VarTemplate, Decl::VarTemplatePartialSpecialization, Decl::Block, Decl::Binding to be complete and on par with classic codegen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable templates are covered in #151066.
I tinkered with Blocks a little bit and it seems like it's not possible to create a BlockDecl without a BlockExpr which requires codegen that's not implemented, yet. Likewise, a BindingDecl can only show up with a DecompositionDecl and while #151073 implements them on a function scope level we don't support them on in namespace scopes, yet. So these DeclKinds would be dead code which is why I didn't add them in this PR.
This patch adds or completes support for a couple of top level declaration types that don't emit any code: Most notably these include Concepts, static_assert and type aliases.